<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="LOGO名称">
          <a-input v-decorator="['logoName', {}]" :readOnly="!!model.id"/>
        </a-form-item>

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户ID">
          <a-input  v-decorator="['userId', {}]" :readOnly="!!model.id"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="审核状态"
        v-if="!!model.id">
          <a-radio-group v-decorator="['examinStatus',{'initialValue':0}]">
            <a-radio :value="1">同意入库</a-radio>
            <a-radio :value="3">拒绝入库</a-radio>
          </a-radio-group>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="备注">
          <a-input placeholder="请输入备注" v-decorator="['remark', {}]"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import Vue from 'vue'
  import {ACCESS_TOKEN} from "@/store/mutation-types"
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "LogoExamineRecordModal",
    data() {
      return {
        title: "操作",
        visible: false,
        picUrl: null,
        uploadLoading: false,
        model: {},
        labelCol: {
          xs: {span: 24},
          sm: {span: 5},
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16},
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {},
        url: {
          fileUpload: window._CONFIG['domianURL'] + "/rest/oss/tx/upload",
          add: "/logoexamine/logoExamineRecord/add",
          edit: "/logoexamine/logoExamineRecord/logoExamine",
        },
      }
    },
    created () {
      const token = Vue.ls.get(ACCESS_TOKEN);
      this.headers = {"X-Access-Token": token}
    },
    computed: {
      uploadAction: function () {
        return this.url.fileUpload;
      }
    },
    methods: {
      /**图片上传**/
      beforeUpload: function (file) {
        var fileType = file.type;
        console.info("文件类型：" + fileType);
      },
      handleChange(info) {
        this.picUrl = "";
        if (info.file.status === 'uploading') {
          this.uploadLoading = true;
          return
        }
        if (info.file.status === 'done') {
          var response = info.file.response;
          this.uploadLoading = false;
          this.model.logoUrl = info.file.response.img_url;
          this.picUrl = "Has no pic url yet";
        }
      },
      getImgUrlView() {
        return this.model.logoUrl;
      },
      add() {
        this.edit({});
      },
      edit(record) {
        if (record.logoUrl != "") {
          this.picUrl = "Has no pic url yet";
        }
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'logoName', 'logoCode', 'contSignAdd', 'contSignDel', 'userId', 'examinStatus', 'logoStatus', 'remark'))
          //时间格式化
        });

      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOk() {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if (!this.model.id) {
              httpurl += this.url.add;
              method = 'post';
            } else {
              httpurl += this.url.edit;
              method = 'post';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化

            console.log(formData)
            httpAction(httpurl, formData, method).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.$emit('ok');
              } else {
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })


          }
        })
      },
      handleCancel() {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>